using UnityEngine;

public class DSS
{
	public const float ReboundDistance = 1f;

	public const float DefenseArea_Angle = 50f;

	public const float NPC_Dunk_SqrDistance_Min = 2.975625f;

	public const float NPC_Dunk_SqrDistance_Max = 9f;

	public const float NPC_Dunk_CloseTwoHand_SqrDistance_Min = 1.265625f;

	public const float NPC_Dunk_CloseTwoHand_SqrDistance_Max = 4.84f;

	public const float NPC_Dunk_CloseOneHand_SqrDistance_Min = 1.21f;

	public const float NPC_Dunk_CloseOneHand_SqrDistance_Max = 4.40999937f;

	public const float NPC_Dunk_CrossLeg_SqrDistance_Min = 15.210001f;

	public const float NPC_Dunk_CrossLeg_SqrDistance_Max = 24.01f;

	public const float NPC_Dunk_TurnAround_SqrDistance_Min = 11.7306242f;

	public const float NPC_Dunk_TurnAround_SqrDistance_Max = 19.5806274f;

	public const float NPC_Dunk_Back_SqrDistance_Min = 22.3256245f;

	public const float NPC_Dunk_BACK_SqrDistance_Max = 27.3006248f;

	public const float NPC_Dunk_CrossLeg2_SqrDistance_Min = 15.4056244f;

	public const float NPC_Dunk_CrossLeg2_SqrDistance_Max = 20.25f;

	public const float NPC_Dunk_FarOneHand_SqrDistance_Min = 11.055625f;

	public const float NPC_Dunk_FarOneHand_SqrDistance_Max = 16f;

	public const float NPC_LayUp_SqrDistance_Stand = 24.01f;

	public const float NPC_LayUp_SqrtDistance_Min = 15.210001f;

	public const float NPC_LayUp_SqrtDistance_Max = 34.81f;

	public const float NPC_LayUp_Back_SqrDistance_Stand = 16f;

	public const float NPC_LayUp_Back_SqrDistance_Min = 10.2400007f;

	public const float NPC_LayUp_Back_SqrDistance_Max = 23.04f;

	public const float NPC_LayUp_EuroStep_SqrDistance_Stand = 9f;

	public const float NPC_LayUp_EuroStep_SqrDistance_Min = 7.29000044f;

	public const float NPC_LayUp_EuroStep_SqrDistance_Max = 14.44f;

	public const float NPC_LayUp_TurnAround_SqrDistance_Stand = 16f;

	public const float NPC_LayUp_TurnAround_SqrDistance_Min = 12.25f;

	public const float NPC_LayUp_TurnAround_SqrDistance_Max = 20.25f;

	public const float NPC_LayUp_Throw_SqrDistance_Stand = 30.25f;

	public const float NPC_LayUp_Throw_SqrDistance_Min = 25f;

	public const float NPC_LayUp_Throw_SqrDistance_Max = 36f;

	public const float NPC_RotateCrossing_Min = 30f;

	public const float NPC_RotateCrossing_Max = 89f;

	public const float NPC_WaitStealTime = 1f;

	public const float NPC_BlockSqrtDistance = 2.25f;

	public const float NPC_BallToJumpHeight = 2.5f;

	public const float NPC_GoBaseLineTime = 2f;

	public const float NPC_StealGrabSqrtDistance = 1f;

	public const float NPC_ChangeOffensePosSqrtDistance = 4f;

	public const float NPC_DefenseHandUpStopTime = 0.8f;

	public const float NPC_FindPosFrequency = 1f;

	public const float sqrDistanceForTurn = 4f;

	public static float distance_sqrt_judge_someone_front = 1f;

	public static bool IsSomeOneFront(Transform myTrans, Vector3 targetPos)
	{
		Vector3 from = targetPos - myTrans.position;
		if (Vector3.Angle(from, myTrans.forward) < 50f && Vector3.Angle(from, myTrans.forward) > -50f && MathHelper.getSqrDistance(targetPos, myTrans.position) < distance_sqrt_judge_someone_front * distance_sqrt_judge_someone_front)
		{
			return true;
		}
		return false;
	}

	public static bool IsCanShoot(Player player)
	{
		float sqrDistance = MathHelper.getSqrDistance(player.getPosition(), (player.getOffenseDirection() != 0) ? Global.posBallIn_Right_Ground : Global.posBallIn_Left_Ground);
		if (sqrDistance < 68.0625f)
		{
			return true;
		}
		return false;
	}

	public static bool IsCanDunk(Player player)
	{
		//if (TutorialController.preTutorialType == TutorialType.Game_Shoot)
		//{
		//	return false;
		//}
		if (player.IsBeingDefense() || (!MyJoystick.isDragging && player.teamType == TeamType.USER && (GameData.IsFinishTutorial /*|| TutorialController.preTutorialType == TutorialType.Game_RealGame*/)))
		{
			return false;
		}
		if (IsInDunkArea(player, DunkType.NORMAL))
		{
			return true;
		}
		if (player.isHaveDunkType(DunkType.TWOHAND) && IsInDunkArea(player, DunkType.TWOHAND))
		{
			return true;
		}
		if (player.isHaveDunkType(DunkType.ONEHAND) && IsInDunkArea(player, DunkType.ONEHAND))
		{
			return true;
		}
		if (player.isHaveDunkType(DunkType.CROSSLEG) && IsInDunkArea(player, DunkType.CROSSLEG))
		{
			return true;
		}
		if (player.isHaveDunkType(DunkType.TURNAROUND) && IsInDunkArea(player, DunkType.TURNAROUND))
		{
			return true;
		}
		if (player.isHaveDunkType(DunkType.BACK) && IsInDunkArea(player, DunkType.BACK))
		{
			return true;
		}
		if (player.isHaveDunkType(DunkType.CROSSLEG2) && IsInDunkArea(player, DunkType.CROSSLEG2))
		{
			return true;
		}
		if (player.isHaveDunkType(DunkType.ONEHAND_FAR) && IsInDunkArea(player, DunkType.ONEHAND_FAR))
		{
			return true;
		}
		return false;
	}

	public static bool IsCanLayUp(Player player)
	{
		//if (TutorialController.preTutorialType == TutorialType.Game_Shoot)
		//{
		//	return false;
		//}
		if (player.IsBeingDefense() || (!MyJoystick.isDragging && player.teamType == TeamType.USER))
		{
			return false;
		}
		if (IsInLayupArea(player, LayupType.NORMAL))
		{
			return true;
		}
		if (player.isHaveLayupType(LayupType.BACK) && IsInLayupArea(player, LayupType.BACK))
		{
			return true;
		}
		if (player.isHaveLayupType(LayupType.EUROSTEP) && IsInLayupArea(player, LayupType.EUROSTEP))
		{
			return true;
		}
		if (player.isHaveLayupType(LayupType.TURNAROUND) && IsInLayupArea(player, LayupType.TURNAROUND))
		{
			return true;
		}
		if (player.isHaveLayupType(LayupType.THROW) && IsInLayupArea(player, LayupType.THROW))
		{
			return true;
		}
		return false;
	}

	public static bool IsInDunkArea(Player player, DunkType dunkType)
	{
		float sqrDistance = MathHelper.getSqrDistance(player.getPosition(), (player.getOffenseDirection() != 0) ? Global.posBallIn_Right_Ground : Global.posBallIn_Left_Ground);
		switch (dunkType)
		{
		case DunkType.NORMAL:
			return sqrDistance >= 2.975625f && sqrDistance <= 9f;
		case DunkType.TWOHAND:
			return sqrDistance >= 1.265625f && sqrDistance <= 4.84f;
		case DunkType.ONEHAND:
			return sqrDistance >= 1.21f && sqrDistance <= 4.40999937f;
		case DunkType.CROSSLEG:
			return sqrDistance >= 15.210001f && sqrDistance <= 24.01f;
		case DunkType.TURNAROUND:
			return sqrDistance >= 11.7306242f && sqrDistance <= 19.5806274f;
		case DunkType.BACK:
			return sqrDistance >= 22.3256245f && sqrDistance <= 27.3006248f;
		case DunkType.CROSSLEG2:
			return sqrDistance >= 15.4056244f && sqrDistance <= 20.25f;
		case DunkType.ONEHAND_FAR:
			return sqrDistance >= 11.055625f && sqrDistance <= 16f;
		default:
			return false;
		}
	}

	public static bool IsInLayupArea(Player player, LayupType layupType)
	{
		float sqrDistance = MathHelper.getSqrDistance(player.getPosition(), (player.getOffenseDirection() != 0) ? Global.posBallIn_Right_Ground : Global.posBallIn_Left_Ground);
		switch (layupType)
		{
		case LayupType.NORMAL:
			return sqrDistance >= 15.210001f && sqrDistance <= 34.81f;
		case LayupType.BACK:
			return sqrDistance >= 10.2400007f && sqrDistance <= 23.04f;
		case LayupType.EUROSTEP:
			return sqrDistance >= 7.29000044f && sqrDistance <= 14.44f;
		case LayupType.TURNAROUND:
			return sqrDistance >= 12.25f && sqrDistance <= 20.25f;
		case LayupType.THROW:
			return sqrDistance >= 25f && sqrDistance <= 36f;
		default:
			return false;
		}
	}

	public static bool IsBeingDefense(Player player, Vector3 paraPos)
	{
		Vector3 from = paraPos - player.getPosition();
		Vector3 to = (player.getOffenseDirection() != 0) ? (Global.posBallIn_Right_Ground - player.getPosition()) : Global.posBallIn_Left_Ground;
		if (Vector3.Angle(from, to) < 50f && Vector3.Angle(from, to) > -50f && MathHelper.getSqrDistance(player.getPosition(), paraPos) < 1.2f)
		{
			return true;
		}
		return false;
	}

	public static Vector3 GetDefensePos(Vector3 targetPos, bool isLeft)
	{
		if (isLeft)
		{
			return (Global.posBallIn_Left_Ground - targetPos).normalized + targetPos;
		}
		return (Global.posBallIn_Right_Ground - targetPos).normalized + targetPos;
	}

	public static float GetThreaten(Vector3 pos, bool isLeft)
	{
		if (isLeft)
		{
			return 50f - MathHelper.getSqrDistance(pos, Global.posBallIn_Left_Ground);
		}
		return 50f - MathHelper.getSqrDistance(pos, Global.posBallIn_Right_Ground);
	}

	public static bool IsPassSuccess(float distance, int data_pass)
	{
		//if (!GameData.IsFinishTutorial && TutorialController.preTutorialType != TutorialType.Game_RealGame)
		//{
		//	return true;
		//}
		if (distance <= 7f)
		{
			return true;
		}
		if (distance > 7f && distance <= 20f)
		{
			return MathHelper.isInPercent(70 + data_pass);
		}
		return MathHelper.isInPercent((float)(70 + data_pass) / 2f);
	}

	public static bool IsWillScore(Player player, bool isLayUp, bool isFreeThrow)
	{
		//if (!GameData.IsFinishTutorial && TutorialController.preTutorialType != TutorialType.Game_RealGame)
		//{
		//	Instance<Ball>.instance.shootPercent = 100;
		//	return true;
		//}
		float num = 0f;
		num += GameHelper.shootDistancePercent[GameHelper.getShootDistanceArea(Vector3.Distance(player.getPosition(), (player.getOffenseDirection() != 0) ? Global.posBallIn_Right_Ground : Global.posBallIn_Left_Ground)) - 1];
		if (isFreeThrow)
		{
			num += (float)player.getData_Shoot(1) * 0.7f;
			num = Mathf.Clamp(num, 20f, 95f);
			Instance<Ball>.instance.shootPercent = (int)num;
			return MathHelper.isInPercent(num);
		}
		if (isLayUp)
		{
			num += 15f;
		}
		else if (player.jumpShootLevel == 1 || player.jumpShootLevel == 3)
		{
			num -= 5f;
		}
		num = ((!player.IsBeingDefense()) ? (num + (float)Random.Range(2, 6)) : (num - 15f));
		if (player.team.data.data_type == 1)
		{
			num += 5f;
		}
		if (GameHelper.IsInThreePointArea(player.getPosition(), player.getOffenseDirection() == OffenseDirection.LEFT))
		{
			num += (float)player.getData_Shoot(3) * 0.7f;
			float num2 = Global.rectCourt.width / 2f;
			Vector3 position = player.getPosition();
			if (num2 - Mathf.Abs(position.z) < 4f)
			{
				num += 10f;
			}
			num += (float)Random.Range(-2, 3);
			num = Mathf.Clamp(num, 5f, 80f);
		}
		else
		{
			num += (float)player.getData_Shoot(2) * 0.7f;
			num += (float)Random.Range(-2, 3);
			num = Mathf.Clamp(num, 20f, 95f);
		}
		Instance<Ball>.instance.shootPercent = (int)num;
		return MathHelper.isInPercent(num);
	}

	public static bool IsStealSuccess(Player player, int data_steal, bool isGrabSteal)
	{
		//if (TutorialController.preTutorialType == TutorialType.Game_Steal)
		//{
		//	Instance<Court>.instance.tutorial.stealCount++;
		//	if (Instance<Court>.instance.tutorial.stealCount == 3)
		//	{
		//		return true;
		//	}
		//	return false;
		//}
		//if (!GameData.IsFinishTutorial && TutorialController.preTutorialType != TutorialType.Game_RealGame)
		//{
		//	return false;
		//}
		int num = 0;
		if (isGrabSteal)
		{
			if (MyScreen.phoneType == PhoneType.LOW)
			{
				return false;
			}
			num = ((data_steal <= 20) ? 10 : ((data_steal > 20 && data_steal <= 40) ? 20 : ((data_steal <= 40 || data_steal > 65) ? 35 : 30)));
			if (player.team.data.data_type == 2)
			{
				num += 5;
			}
		}
		else
		{
			if (player.team.data.data_type == 2)
			{
				num += 5;
			}
			num = ((data_steal <= 20) ? 25 : ((data_steal > 20 && data_steal <= 40) ? 30 : ((data_steal <= 40 || data_steal > 65) ? 50 : 35)));
			num = ((!(Instance<Court>.instance.teamUser.getPlayer_ControlBall() != player)) ? Mathf.Clamp(num, 50, 80) : Mathf.Clamp(num, 30, 70));
		}
		return MathHelper.isInPercent((float)num / 2f);
	}

	public static bool IsBlockSuccess(Player player)
	{
		//if (!GameData.IsFinishTutorial && TutorialController.preTutorialType != TutorialType.Game_RealGame)
		//{
		//	return false;
		//}
		if (Instance<Court>.instance.teamUser.getPlayer_ControlBall() == player)
		{
			return true;
		}
		float num = player.getData_Block() + 10;
		if (player.team.data.data_type == 2)
		{
			num += 5f;
		}
		num = Mathf.Clamp(num, 25f, 45f);
		return MathHelper.isInPercent(num);
	}

	public static bool IsChargingFoul(Player player_offense, Player player_defense)
	{
		return false;
	}

	public static Player whoFoul(Player player_offense, Player player_defense)
	{
		if (MathHelper.isInPercent((float)player_offense.getData_Level() / (float)(player_offense.getData_Level() + player_defense.getData_Level()) * 100f))
		{
			return player_defense;
		}
		return player_offense;
	}

	public static bool IsStealFoul(Player player_offense, Player player_defense)
	{
		return false;
	}

	public static bool IsBlockFoul(Player player_offense, Player player_defense)
	{
		//if (!GameData.IsFinishTutorial && TutorialController.preTutorialType != TutorialType.Game_RealGame)
		//{
		//	return false;
		//}
		return MathHelper.isInPercent(GameHelper.blockFoulPercent[Mathf.Abs(player_offense.getData_Physical() - player_defense.getData_Physical())]);
	}
}
